package com.hurteng.stormplane.comm;

import android.util.Log;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;

public class CommInitThread extends Thread {
    private InetAddress address;
    private InetSocketAddress socketAddress;
    private InputStream inputStream;
    private OutputStream outputStream;

    public CommInitThread(String ip, int port) {
        try {
            address = InetAddress.getByName(ip);
            socketAddress = new InetSocketAddress(address, port);
        } catch (Exception e) {
            Log.d("qinjinyu", e.getMessage());
        }
    }

    public InputStream getInputStream() {
        return inputStream;
    }

    public OutputStream getOutputStream() {
        return outputStream;
    }

    @Override
    public void run() {
        super.run();

        try {
            Socket socket = new Socket();
            socket.connect(socketAddress);
            inputStream = socket.getInputStream();
            outputStream = socket.getOutputStream();
        } catch (Exception e) {
            Log.d("qinjinyu", e.getMessage());
        }
    }
}
